import ply.lex as lex

reserved = {
	'select'	: 'SELECT',
	'from'		: 'FROM',
	'where'		: 'WHERE',
	'and'		: 'AND',
	'or'		: 'OR',
	'join'		: 'JOIN',
	'on'		: 'ON',
}

tokens = [
	'NAME',
	'STRING',
	'COMMA',
	'DOT',
	'COLON',
	'OP',
	#'SPACE',
] + list(reserved.values())

t_STRING	= r"'[a-zA-Z_0-9]+'"
t_COMMA		= r','
t_DOT		= r'\.'
t_COLON		= r':'
t_OP		= r'<|>|=|!='
#t_SPACE		= r'[ \t\n]+'
t_ignore	= ' \t\n'

def t_NAME (t):
	r'[a-zA-Z][a-zA-Z0-9\-_]*'
	t.type =  reserved.get(t.value, 'NAME')
	return t


lexer = lex.lex()

if __name__ == '__main__':
	test_sql = '''
	select Asset_100000.MetaData:vendor, Event.MetaData:id
	from Asset join Event on Asset.MetaData:id = Event.MetaData:id
	where Asset.MetaData:vendor = 'hp'
	'''

	lexer.input(test_sql)
	while True:
		tok = lexer.token()
		if not tok: break
		print tok
